<!-- Followers.vue -->
<template>
  <div class="followers-management">
    <div class="card">
      <div class="card-header">
        <h2>我的粉丝</h2>
        <button class="btn-refresh" @click="fetchFollowers">
          <i class="icon-refresh"></i> 刷新
        </button>
      </div>

      <div class="table-container">
        <table>
          <thead>
          <tr>
            <th>粉丝名称</th>
            <th>头像</th>
            <th>关注时间</th>
            <th>操作</th>
          </tr>
          </thead>
          <tbody>
          <tr v-for="follower in followers" :key="follower.id">
            <td>{{ follower.name }}</td>
            <td>
              <img :src="follower.avatar" class="avatar" alt="头像">
            </td>
            <td>{{ $formatDate(follower.followTime) }}</td>
            <td>
              <button class="btn-view" @click="handleView(follower)">
                <i class="icon-eye"></i> 查看
              </button>
            </td>
          </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Followers',
  data() {
    return {
      followers: [],
      loading: false
    }
  },
  created() {
    this.fetchFollowers();
  },
  methods: {
    async fetchFollowers() {
      const storedUser = localStorage.getItem('user');
      this.user = storedUser ? JSON.parse(storedUser) : null;
      const uid = storedUser ? JSON.parse(storedUser).uid : null;

      try {
        const response = await this.$axios.get(`/api/percenter/followers`, {
          params: { uid }
        });
        this.followers = response.data.data;
      } catch (error) {
        this.$message.error('获取粉丝失败');
      }
    },
  }
}
</script>

<style scoped>
.followers-management {
  padding: 20px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.btn-view {
  padding: 6px 12px;
  background-color: #2196f3;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.btn-view i {
  margin-right: 5px;
}
</style>